/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FiltrosRanking.java
 *
 * Created on Apr 14, 2011, 9:53:31 PM
 */

package forms;

import beans.Barrio;
import beans.Boliche;
import beans.Profesion;
import java.util.ArrayList;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import managers.ManagerReporting;

/**
 *
 * @author nMoncho
 */
public class FiltrosRanking extends javax.swing.JFrame {

    private ManagerReporting gestor;
    private ArrayList<JCheckBox> checkBarrios = new ArrayList<JCheckBox>();
    private ArrayList<JCheckBox> checkProfesiones = new ArrayList<JCheckBox>();

    /** Creates new form FiltrosRanking */
    public FiltrosRanking(ManagerReporting gestor) {
        initComponents();
        //panelBarrios.setLayout(new BoxLayout(panelBarrios, BoxLayout.Y_AXIS));
        //panelProfesion.setLayout(new BoxLayout(panelProfesion, BoxLayout.Y_AXIS));
        this.gestor = gestor;

        //Boliches
        for(Boliche boliche : gestor.getBoliches()){
            comboBoliche.addItem(boliche);
        }
        //Sexo
        comboSexo.addItem(" ");
        comboSexo.addItem("Masculino");
        comboSexo.addItem("Femenino");
        comboSexo.setSelectedIndex(0);

        //Barrios
        JCheckBox check;
        for(Barrio barrio : gestor.getBarrios()){
            check = new JCheckBox(barrio.getNombre());
            panelBarrios.add(check);
            checkBarrios.add(check);
        }
        panelBarrios.add(Box.createVerticalGlue());

        //Profesion
        for(Profesion profesion : gestor.getProfesiones()){
            check = new JCheckBox(profesion.getNombre());
            panelProfesion.add(check);
            checkProfesiones.add(check);
        }
        panelProfesion.add(Box.createVerticalGlue());

        panelBarrios.revalidate();
        panelBarrios.repaint();
        panelProfesion.revalidate();
        panelProfesion.repaint();
        this.setVisible(true);

        this.setLocation(100, 50);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelTabulado = new javax.swing.JTabbedPane();
        tabFiltrosBasicos = new javax.swing.JPanel();
        labelBoliche = new javax.swing.JLabel();
        comboBoliche = new javax.swing.JComboBox();
        labelSexo = new javax.swing.JLabel();
        comboSexo = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        checkConvocante = new javax.swing.JCheckBox();
        checkConsumidor = new javax.swing.JCheckBox();
        checkRelevante = new javax.swing.JCheckBox();
        tabFiltroBarrios = new javax.swing.JPanel();
        panelBarriosScroll = new javax.swing.JScrollPane();
        panelBarrios = new javax.swing.JPanel();
        tabFiltroProfesion = new javax.swing.JPanel();
        panelProfesionScroll = new javax.swing.JScrollPane();
        panelProfesion = new javax.swing.JPanel();
        botonFiltrar = new javax.swing.JButton();
        botonCerrar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Filtros para Ranking de Socios");
        setIconImage(new ImageIcon(getClass().getResource("/resources/arrow-branch-bgr-16-ns.png")).getImage());

        tabFiltrosBasicos.setBorder(javax.swing.BorderFactory.createTitledBorder("Filtros Disponibles"));

        labelBoliche.setText("Boliche: ");

        comboBoliche.setToolTipText("Selecciona el bolche");

        labelSexo.setText("Sexo:");

        jLabel1.setText("Razon de Socio:");

        checkConvocante.setText("Convocante");

        checkConsumidor.setText("Consumidor");

        checkRelevante.setText("Relevante");

        javax.swing.GroupLayout tabFiltrosBasicosLayout = new javax.swing.GroupLayout(tabFiltrosBasicos);
        tabFiltrosBasicos.setLayout(tabFiltrosBasicosLayout);
        tabFiltrosBasicosLayout.setHorizontalGroup(
            tabFiltrosBasicosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabFiltrosBasicosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabFiltrosBasicosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelBoliche)
                    .addComponent(labelSexo))
                .addGap(18, 18, 18)
                .addGroup(tabFiltrosBasicosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(comboSexo, 0, 108, Short.MAX_VALUE)
                    .addComponent(comboBoliche, 0, 108, Short.MAX_VALUE))
                .addGap(36, 36, 36)
                .addGroup(tabFiltrosBasicosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(tabFiltrosBasicosLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(checkConvocante)))
                .addGap(6, 6, 6)
                .addGroup(tabFiltrosBasicosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(checkRelevante)
                    .addComponent(checkConsumidor))
                .addContainerGap(80, Short.MAX_VALUE))
        );
        tabFiltrosBasicosLayout.setVerticalGroup(
            tabFiltrosBasicosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabFiltrosBasicosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabFiltrosBasicosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tabFiltrosBasicosLayout.createSequentialGroup()
                        .addGroup(tabFiltrosBasicosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(checkConsumidor))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(tabFiltrosBasicosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(checkRelevante)
                            .addComponent(checkConvocante)))
                    .addGroup(tabFiltrosBasicosLayout.createSequentialGroup()
                        .addGroup(tabFiltrosBasicosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelBoliche)
                            .addComponent(comboBoliche, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(tabFiltrosBasicosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelSexo)
                            .addComponent(comboSexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(42, Short.MAX_VALUE))
        );

        panelTabulado.addTab("Filtros Basicos", tabFiltrosBasicos);

        panelBarriosScroll.setBorder(javax.swing.BorderFactory.createTitledBorder("Barrios"));

        panelBarrios.setLayout(new javax.swing.BoxLayout(panelBarrios, javax.swing.BoxLayout.Y_AXIS));
        panelBarriosScroll.setViewportView(panelBarrios);

        javax.swing.GroupLayout tabFiltroBarriosLayout = new javax.swing.GroupLayout(tabFiltroBarrios);
        tabFiltroBarrios.setLayout(tabFiltroBarriosLayout);
        tabFiltroBarriosLayout.setHorizontalGroup(
            tabFiltroBarriosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelBarriosScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 484, Short.MAX_VALUE)
        );
        tabFiltroBarriosLayout.setVerticalGroup(
            tabFiltroBarriosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelBarriosScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE)
        );

        panelTabulado.addTab("Filtro por Barrio", tabFiltroBarrios);

        panelProfesionScroll.setBorder(javax.swing.BorderFactory.createTitledBorder("Estudio"));

        panelProfesion.setLayout(new javax.swing.BoxLayout(panelProfesion, javax.swing.BoxLayout.Y_AXIS));
        panelProfesionScroll.setViewportView(panelProfesion);

        javax.swing.GroupLayout tabFiltroProfesionLayout = new javax.swing.GroupLayout(tabFiltroProfesion);
        tabFiltroProfesion.setLayout(tabFiltroProfesionLayout);
        tabFiltroProfesionLayout.setHorizontalGroup(
            tabFiltroProfesionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelProfesionScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 484, Short.MAX_VALUE)
        );
        tabFiltroProfesionLayout.setVerticalGroup(
            tabFiltroProfesionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelProfesionScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE)
        );

        panelTabulado.addTab("Filtro por Estudio", tabFiltroProfesion);

        botonFiltrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/badge-square-check-16-ns.png"))); // NOI18N
        botonFiltrar.setText("Filtrar");
        botonFiltrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonFiltrarActionPerformed(evt);
            }
        });

        botonCerrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/badge-square-cross-16-ns.png"))); // NOI18N
        botonCerrar.setText("Cerrar");
        botonCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCerrarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panelTabulado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(botonFiltrar)
                        .addGap(18, 18, 18)
                        .addComponent(botonCerrar)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(panelTabulado, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonCerrar)
                    .addComponent(botonFiltrar))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botonFiltrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonFiltrarActionPerformed
        Boliche boliche = (Boliche)comboBoliche.getSelectedItem();
        String sexo = (String)comboSexo.getSelectedItem();
        String[] razones = null;
        int lengthRazones = 0;
        lengthRazones += (checkConsumidor.isSelected() ? 1 : 0);
        lengthRazones += (checkConvocante.isSelected() ? 1 : 0);
        lengthRazones += (checkRelevante.isSelected() ? 1 : 0);
        if(lengthRazones > 0){
            razones = new String[lengthRazones];
            int i = 0;
            if(checkConsumidor.isSelected()){
                razones[i] = "CONSUMIDOR";
                i++;
            }
            if(checkConvocante.isSelected()){
                razones[i] = "CONVOCANTE";
                i++;
            }
            if(checkRelevante.isSelected()){
                razones[i] = "RELEVANTE";
            }
        }
        ArrayList<String> checkadosBarrios = new ArrayList<String>();
        for(JCheckBox check : checkBarrios){
            if(check.isSelected())
                checkadosBarrios.add(check.getText());
        }
        String[] barrios = null;
        if(checkadosBarrios.size()>0){
            barrios = new String[checkadosBarrios.size()];
            checkadosBarrios.toArray(barrios);
        }
        
        ArrayList<String> checkadosEstudios = new ArrayList<String>();
        for(JCheckBox check : checkProfesiones){
            if(check.isSelected())
                checkadosEstudios.add(check.getText());
        }
        String[] estudios = null;
        if(checkadosEstudios.size()>0){
            estudios = new String[checkadosEstudios.size()];
            checkadosEstudios.toArray(estudios);
        }

        gestor.realizarFiltro(boliche, sexo, razones, barrios, estudios);
    }//GEN-LAST:event_botonFiltrarActionPerformed

    private void botonCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCerrarActionPerformed
        this.dispose();
    }//GEN-LAST:event_botonCerrarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonCerrar;
    private javax.swing.JButton botonFiltrar;
    private javax.swing.JCheckBox checkConsumidor;
    private javax.swing.JCheckBox checkConvocante;
    private javax.swing.JCheckBox checkRelevante;
    private javax.swing.JComboBox comboBoliche;
    private javax.swing.JComboBox comboSexo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel labelBoliche;
    private javax.swing.JLabel labelSexo;
    private javax.swing.JPanel panelBarrios;
    private javax.swing.JScrollPane panelBarriosScroll;
    private javax.swing.JPanel panelProfesion;
    private javax.swing.JScrollPane panelProfesionScroll;
    private javax.swing.JTabbedPane panelTabulado;
    private javax.swing.JPanel tabFiltroBarrios;
    private javax.swing.JPanel tabFiltroProfesion;
    private javax.swing.JPanel tabFiltrosBasicos;
    // End of variables declaration//GEN-END:variables

    
}
